package com.yl.plugin.method;

import com.yl.plugin.method.base.BaseMethod;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.JavaVisibility;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.api.dom.xml.Attribute;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;

import java.util.*;

/**
 * @author liuxubo
 */
public class AddMethod implements BaseMethod {
    @Override
    public int order() {
        return 4;
    }

    @Override
    public Method buildMethod(IntrospectedTable introspectedTable) {
        JavaVisibility methodVisibility = JavaVisibility.PUBLIC;

        FullyQualifiedJavaType methodReturnType = new FullyQualifiedJavaType("int");

        FullyQualifiedJavaType fullyQualifiedJavaType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
        Parameter methodParameter = new Parameter(fullyQualifiedJavaType, StringUtils.uncapitalize(fullyQualifiedJavaType.getShortName()));

        Method method = new Method("add");
        method.setVisibility(methodVisibility);
        method.setReturnType(methodReturnType);
        method.addParameter(methodParameter);

        method.addJavaDocLine("/**");
        method.addJavaDocLine(" * 新增");
        method.addJavaDocLine(" * ");
        method.addJavaDocLine(" * @param " + methodParameter.getName());
        method.addJavaDocLine(" */");

        return method;
    }

}
